package top.api.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResUlt;
import top.api.domain.dto.*;
import top.api.service.ClassService;
import top.api.service.StudentService;

import java.util.List;

@RestController
@RequestMapping("/student")
@RequiredArgsConstructor
@Api(tags = "学生管理")
public class StudentController {
    private final StudentService baseService;

    @GetMapping
    @SaCheckRole("admin")
    @ApiOperation("分页查询")
    public ResUlt<?> pageList(@Validated PageDto pageDto, Integer id,Integer classno,String name){
        return baseService.pageList(pageDto,id,classno,name);
    }

    @GetMapping("/{id}")
    @SaCheckRole("admin")
    @ApiOperation("查询学生详情")
    public ResUlt<?> getStudentInfo(@PathVariable Integer id){
        return baseService.getStudentInfo(id);
    }

    @PostMapping
    @SaCheckRole("admin")
    @ApiOperation("添加学生")
    public ResUlt<?> addStudent(@RequestBody @Validated StudentAddDto studentAddDto){
        return baseService.addStudent(studentAddDto);
    }

    @PutMapping
    @SaCheckRole("admin")
    @ApiOperation("修改学生")
    public ResUlt<?> editStudent(@RequestBody @Validated StudentEditDto studentEditDto){
        return baseService.editStudent(studentEditDto);
    }

    @DeleteMapping("/{ids}")
    @SaCheckRole("admin")
    @ApiOperation("删除学生")
    public ResUlt<?> delStudent(@PathVariable List<Integer> ids){
        return baseService.delStudent(ids);
    }
}
